package top.lixunda.ecommerce.server.user.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import top.lixunda.commerce.common.core.entity.MessageObject;
import top.lixunda.ecommerce.server.business.BaseController;
import top.lixunda.ecommerce.server.user.api.controller.IUserRoleController;
import top.lixunda.ecommerce.server.user.api.entity.dto.UserRoleInsertDTO;
import top.lixunda.ecommerce.server.user.api.entity.dto.UserRoleRemoveDTO;
import top.lixunda.ecommerce.server.user.service.IUserRoleService;

import java.util.List;

/**
 * 用户角色分配管理接口
 *
 * @author lixunda
 * @version time:2020/4/26 16:21
 */
@Slf4j
@RestController
public class UserRoleController extends BaseController implements IUserRoleController {

    private final IUserRoleService userRoleService;

    @Autowired
    public UserRoleController(IUserRoleService userRoleService) {
        this.userRoleService = userRoleService;
    }

    /**
     * 分配角色
     *
     * @param list 角色操作DTO
     * @return 是否保存成功
     */
    @Override
    public MessageObject<Boolean> allotStoreRole(List<UserRoleInsertDTO> list) {
        Boolean result = userRoleService.allotStoreRole(list);
        return getSuccessMessageObject("添加角色成功", result);
    }

    /**
     * 分配角色
     *
     * @param list 角色操作DTO
     * @return 是否保存成功
     */
    @Override
    public MessageObject<Boolean> allotAdminRole(List<UserRoleInsertDTO> list) {
        Boolean result = userRoleService.allotAdminRole(list);
        return getSuccessMessageObject("添加角色成功", result);
    }

    /**
     * 移除角色
     *
     * @param list 角色操作DTO
     * @return 是否移除成功
     */
    @Override
    public MessageObject<Boolean> removeStoreRoleAllot(List<UserRoleRemoveDTO> list) {
        Boolean result = userRoleService.removeStoreRoleAllot(list);
        return getSuccessMessageObject("移除角色成功", result);
    }

    /**
     * 移除管理系统角色
     *
     * @param list 角色操作DTO
     * @return 是否移除成功
     */
    @Override
    public MessageObject<Boolean> removeAdminRoleAllot(List<UserRoleRemoveDTO> list) {
        Boolean result = userRoleService.removeAdminRoleAllot(list);
        return getSuccessMessageObject("移除角色成功", result);
    }

    /**
     * 根据分配编号移除角色分配
     *
     * @param list 分配编号列表
     * @return 是否移除成功
     */
    @Override
    public MessageObject<Boolean> removeStoreRoleAllotByIds(List<Integer> list) {
        Boolean result = userRoleService.removeStoreRoleAllotByIds(list);
        return getSuccessMessageObject("移除角色成功", result);
    }

    /**
     * 根据分配编号移除管理系统角色分配
     *
     * @param list 分配编号列表
     * @return 是否移除成功
     */
    @Override
    public MessageObject<Boolean> removeAdminRoleAllotByIds(List<Integer> list) {
        Boolean result = userRoleService.removeAdminRoleAllotByIds(list);
        return getSuccessMessageObject("移除角色成功", result);
    }
}
